package com.mjk.common.tools.gson.adapter.impl;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.mjk.common.tools.logger.BizLogger;
import com.mjk.common.util.ClobUtils;

import javax.sql.rowset.serial.SerialClob;
import java.io.IOException;

public class SerialClobTypeAdapterImpl extends TypeAdapter<SerialClob> {
    @Override
    public void write(JsonWriter jsonWriter, SerialClob serialClob) throws IOException {
        jsonWriter.value(ClobUtils.clobToString(serialClob));
    }

    @Override
    public SerialClob read(JsonReader jsonReader) throws IOException {
        try {
            return new SerialClob(jsonReader.nextString().toCharArray());
        } catch (Exception e) {
            BizLogger.error(e);
        }
        return null;
    }
}
